package com.gnerv.rabbitmq.agent.mapper;

import com.gnerv.rabbitmq.agent.command.CommonCommand;
import com.gnerv.rabbitmq.agent.command.NodeCommand;
import com.gnerv.rabbitmq.agent.handler.PingExecResultHandler;
import com.gnerv.rabbitmq.agent.model.entity.Node;
import com.gnerv.rabbitmq.agent.tools.ExecTools;
import lombok.extern.slf4j.Slf4j;

/**
 * @author Gnerv LiGen
 */
@Slf4j
public class NodeMapper extends BaseMapper {

    private NodeMapper(Node node){
        super();
        setNode(node);
    }

    public static NodeMapper build(Node node){
        return new NodeMapper(node);
    }

    public String getNodeStatus(){
        ExecTools.ExecResult status = NodeCommand.build(getNode()).status();
        return null;
    }

    public boolean isRunning(String targetNode){
        ExecTools.ExecResult ping = CommonCommand.build(getNode()).ping(targetNode);
        return PingExecResultHandler.handle(ping);
    }

}
